package com.serviceImpl;

import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.dao.DepartmentMapper;
import com.pojo.Department;
import com.service.IDepartmentService;

@Transactional(propagation = Propagation.REQUIRED, isolation = Isolation.DEFAULT, timeout = 5)
@Service("departmentService")
public class DepartmentServiceImpl implements IDepartmentService {
	@Resource
	private DepartmentMapper departmentMapper;

	@Override
	public Department createDepartment(Department department) {
		departmentMapper.insert(department);
		return department;
	}

	@Override
	public void deleteDepartment(int departmentId) {
		departmentMapper.deleteByPrimaryKey(departmentId);
	}

	@Override
	public void deleteDepartments(int departmentId) {
		departmentMapper.deldepartments(departmentId);
	}

	@Override
	public List<Department> getDepartments(int page, int groups) {
		return departmentMapper.getall((page-1)*groups,groups);
	}
	
	public List<Department> getDepartments(){
		return departmentMapper.getDepartments();
	}

	@Override
	public Department getDepartmentByid(int departmentid) {
		return departmentMapper.selectByPrimaryKey(departmentid);
	}

	@Override
	public Department updateDepartment(Department department) {
		departmentMapper.updateByPrimaryKey(department);
		return department;
	}

	@Override
	public int getCounts() {
		return departmentMapper.getCounts();
	}

}
